<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of article
 *
 * @author Snake8xO2
 */
class Article extends CI_Model {
    //put your code here
    function __construct() {
        parent::__construct();
    }
    
    function get_recent_articles() {
        $recent_posts = wp_get_recent_posts();
        $articles = array();
        foreach ($recent_posts as $post) {
            $articles[] = $this->convert_post_to_article($post);
        }
        //print_r($articles);
        return $articles;
    }
    
    function get_article($post_id) {
        $post = wp_get_single_post($post_id, ARRAY_A);
        return $this->convert_post_to_article($post);
    }
    
    function convert_post_to_article($post) {
        $category = get_the_category($post['post_category']);
        $category = $category[0];
        $article = array(
                            'id' => $post['ID'],
                            'title' => $post['post_title'],
                            'time' => mysql2date('g:i a', $post['post_date']),
                            'date' => mysql2date('F j, Y', $post['post_date']),
                            'fulltime' => $post['post_date'],
                            'author' => (get_userdata($post['post_author'])->user_nicename),
                            'author_id' => $post['post_author'],
                            'comment_count' => $post['comment_count'],
                            'entry_content' => $post['post_content'],
                            'category' => $category->name,
                            'category_id' => $post['post_category']
                        );        
        return $article;
    }
}

?>
